from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base, sessionmaker

from database.mysql_utils import MysqlUtils

Base = declarative_base()


class AmzAccount(Base):
    __tablename__ = 'amz_account'
    id = Column(String(255), primary_key=True)
    ip = Column(String(255))
    platform = Column(String(255))
    name = Column(String(255))
    username = Column(String(255))
    siteId = Column(String(255))
    proxyId = Column(String(255))
    lastuserId = Column(String(255))
    lastusetime = Column(String(255))
    createtime = Column(String(255))
    siteName = Column(String(255))
    packageName = Column(String(255))
    platformName = Column(String(255))


Base.metadata.create_all(MysqlUtils.mysql_connect())
Session = sessionmaker(bind=MysqlUtils.mysql_connect())


class AmzAccountData:

    @staticmethod
    def insert_amz_account_info():
        account_list = [{'id': '27416847848366', 'ip': '101.33.125.208', 'platform': '美国亚马逊', 'name': '23年(Qu跟卖号)', 'username': 'xcyh-us@outlook.com', 'siteId': '1', 'proxyId': '4393475', 'lastuserId': '17170399645030', 'lastusetime': '2025-03-13 09:25:16', 'createtime': '2025-03-11 17:19:44', 'siteName': '美国', 'packageName': '中国香港腾讯云1', 'platformName': '亚马逊'}]

        session = Session()
        for account in account_list:
            id = account.get("id")
            ip = account.get("ip")
            platform = account.get("platform")
            name = account.get("name")
            username = account.get("username")
            siteId = account.get("siteId")
            proxyId = account.get("proxyId")
            lastuserId = account.get("lastuserId")
            lastusetime = account.get("lastusetime")
            createtime = account.get("createtime")
            siteName = account.get("siteName")
            packageName = account.get("packageName")
            platformName = account.get("platformName")
            account_obj = AmzAccount(id=id, ip=ip, platform=platform, name=name, username=username, siteId=siteId,
                                     proxyId=proxyId, lastuserId=lastuserId, lastusetime=lastusetime,
                                     createtime=createtime, siteName=siteName, packageName=packageName,
                                     platformName=platformName)
            session.add(account_obj)
            session.commit()
        session.close()


if __name__ == '__main__':
    AmzAccountData.insert_amz_account_info()